package com.welsmann.app.start.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.mysql.jdbc.StringUtils;
import com.welsmann.app.start.dao.ISiteDAO;
import com.welsmann.app.start.dao.ISiteTypeDAO;
import com.welsmann.app.start.entity.Site;
import com.welsmann.app.start.entity.SiteType;
import com.welsmann.app.start.service.BaseService;
import com.welsmann.app.start.service.ISiteService;

@Service("SiteService")
@Transactional(readOnly = true)
public class SiteService extends BaseService implements ISiteService {

	@Resource(name = "SiteDAO")
	private ISiteDAO siteDAO;
	
	@Resource(name = "SiteTypeDAO")
	private ISiteTypeDAO siteTypeDAO;

	@Override
	public List<Site> getTopAll() {
		return siteDAO.getTopAll();
	}

	@Override
	public Site getById(String id) {
		return siteDAO.getById(id);
	}

	@Override
	public Site getByAlias(String alias) {
		return StringUtils.isEmptyOrWhitespaceOnly(alias) ? null : siteDAO
				.getByAlias(alias);
	}
	
	@Override
	public List<SiteType> getAllSiteType() {
		return siteTypeDAO.getAll();
	}
	
	@Override
	public List<Site> getTopByType(String typeId) {
		return siteDAO.getTypeTop(typeId);
	}
	
	@Transactional(readOnly = false)
	@Override
	public Site clickByAlias(String alias) {
		Site site = siteDAO.getByAlias(alias);
		if (site != null) {
			siteDAO.click(site.getId());
		}
		return site;
	}

}
